import { reactive } from 'vue'
import { defineStore } from 'pinia'

export const useUserStore = defineStore(
  'user',
  () => {
    //用户基本信息
    const userInfo = reactive({
      avatar: null,
      role: '0',
      username: 'zhangsan',
    })

    const logout = async () => {
      sessionStorage.clear()
      localStorage.clear()
      window.top!.location.href = '/'
    }
    return {
      userInfo,
      logout,
    }
  },
  {
    // persist: true,//持久存储
    persist: {
      storage: sessionStorage, //存储到sessionStorage默认localStorage
      key: 'user',
    },
  },
)
